home *** CD-ROM | disk | FTP | other *** search
- Path: inforamp.net!ts26-13
- From: rmorin@inforamp.net (Randy Charles Morin)
- Newsgroups: comp.lang.c++
- Subject: Re: Help! I am baffled! (newbie) - problem.txt [1/1]
- Date: Tue, 06 Feb 96 22:38:38 GMT
- Organization: MiddleWorld SoftWare
- Message-ID: <4f8kvg$ffl@sam.inforamp.net>
- References: <4euosb$qnj@atlas.uniserve.com>
- NNTP-Posting-Host: ts26-13.tor.inforamp.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <4euosb$qnj@atlas.uniserve.com>, nowher@anyplace.com (Chris) wrote:
- >
- >TempPart.PartNum = new char[15];
- >...
- >TempPart.PartNum=TempStr;
- >
-
- Here's your problem. You allocate a string in the first statement. Thus you
- have a string that is pointed to by TempPart.PartNum. Then you set
- TempPart.PartNum to TempStr. This does not copy the string, this only changes
- the pointer. Now that first string you pointed to is lost in space and you
- are running into big pointer problems when TempStr get deallocated. To copy a
- string use strcpy or a variant of it. I might be wrong, since you included
- only a portion of the code.
-
- Agrivar
-